//
//  WriteComment.m
//  HappyStore
//
//  Created by 李小辉 on 16/11/3.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "WriteComment.h"

@implementation WriteComment


- (instancetype)init{
    self = [super init];
//    [self setFrame:CGRectMake(0, screenH - 48, screenW, 48)];
    self.backgroundColor = [UIColor colorWithHexString:@"#eeeeee" alpha:1.0f];
    UITextField *textContentTextField = [[UITextField alloc] initWithFrame:CGRectMake(8, 9, screenW - 16, 30)];
    textContentTextField.placeholder = @"写评论";
    [textContentTextField addTarget:self action:@selector(endEdit:) forControlEvents:UIControlEventEditingDidEnd];
    textContentTextField.borderStyle = UITextBorderStyleRoundedRect;
    [self addSubview:textContentTextField];
    
    //成为第一响应者
    [textContentTextField becomeFirstResponder];
    
    return self;
}
- (void)endEdit: (UITextField *)sender{
    [self removeFromSuperview];
    
    if (sender.text.length != 0) {

        NSMutableDictionary * dic = [NSMutableDictionary dictionary];
        //token=评论用户的token&resId=资源id&content=内容&userId=评论用的id&userName=评论用户的用户名
        dic[@"userId"] = [USER_DEFAULTS objectForKey:@"userid"];
        dic[@"userName"] = [USER_DEFAULTS objectForKey:@"account"];
        dic[@"token"] = [USER_DEFAULTS objectForKey:@"token"];
        dic[@"resId"] = self.resId;
        
        dic[@"content"] = sender.text;
        
        [LSHttpTool sendHttpData:self.urlStr params:dic success:^(id responseObject) {
            NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
            
            [[NSNotificationCenter defaultCenter] postNotificationName:@"updatePinlun" object:nil userInfo:dicInfo];
            
        } failure:^(NSError *error) {

            [self showSingleIconBubble:@"网络连接错误"];
        }];
    }
    
}


@end
